﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MLM.AdminCP.Class;
using Telerik.Web.UI;
using MLM.Base;
using System.Data;
using System.Collections;
using MLM.Data;

namespace MLM.AdminCP.Pages
{
    public partial class ProductPrice : BasePage
    {
        protected override void OnInit(EventArgs e)
        {
            Permission.CheckIsAdmin();
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RadProductPriceGrid.ItemUpdated += new GridUpdatedEventHandler(radProductPriceGrid_ItemUpdated);
            RadProductPriceGrid.ItemInserted += new GridInsertedEventHandler(radProductPriceGrid_ItemInserted);
            RadProductPriceGrid.ItemDeleted += new GridDeletedEventHandler(radProductPriceGrid_ItemDeleted);
            //  RadProductPriceGrid.ItemCommand += new GridCommandEventHandler(RadProductPriceGrid_ItemCommand);
        }

        void RadProductPriceGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            //if (e.CommandName == RadGrid.PerformInsertCommandName)
            //{
            //    GridEditableItem editedItem = e.Item as GridEditableItem;

            //    //Create new row in the DataSource
            //    Data.ProductPrice productPrice = new Data.ProductPrice();
            //    productPrice.Price = double.Parse((editedItem.FindControl("PriceTxt") as RadNumericTextBox).Text);
            //    //Insert new values
            //    Message.ShowError(productPrice.Price + "");
            //    Hashtable newValues = new Hashtable();
            //}
        }
        void radProductPriceGrid_ItemDeleted(object sender, GridDeletedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                Message.ShowError("ProductPrice " + e.Item["ProductPriceID"].Text + " cannot be deleted. Reason: " + e.Exception.Message);
            }
            else
            {
                Message.ShowSuccess("ProductPrice " + e.Item["ProductPriceID"].Text + " deleted!");
            }
        }

        void radProductPriceGrid_ItemInserted(object sender, GridInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                Message.ShowError("ProductPrice cannot be inserted. Reason: " + e.Exception.Message);
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
            }
            else
            {
                Message.ShowSuccess("ProductPrice inserted!");
            }
        }

        void radProductPriceGrid_ItemUpdated(object sender, GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                Message.ShowError("ProductPrice " + e.Item["ProductPriceID"].Text + " cannot be updated. Reason: " + e.Exception.Message);                
            }
            else
            {
                Message.ShowSuccess("ProductPrice " + e.Item["ProductPriceID"].Text + " updated.");
            }
        }
    }
}